<!DOCTYPE html>
<html style="width:100%;">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>端API</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/yzl.css"/>
    <style>
        .active {
            background-color: #ffffff;
            color: #9d0152;
        }
    </style>
</head>
<body style="width:100%;">
  <div class="header" id="app" v-cloak>
    <img style="position: absolute;left:11px;top:26px;width:24px;height:24px;"
         v-src="'../../image/home_icon_scanner.png'" tapmode v-myclick="scanner">
      <div class="shopsearch" onclick="openSearch()">
          <img class="icon-search" src="../../image/search.png">
          <input placeholder="您想找什么" tapmode disabled>
      </div>
      <img onclick="openMessage()"  style="position:absolute;right:11px;top:25px;;width:24px;height:24px;"
           v-src="'../../image/user_icon_search_msg.png'" tapmode>
      <span style="position:absolute;font-size:12px;right:25px;top:20px;color:white;background:red;line-height:normal;padding:0 5px;border-radius:7px;z-index: 10"
        v-if="unReadMsgCount>0">{{unReadMsgCount}}</span>
  </div>
</body>
<script src="../../script/vue.js"></script>
<script src="../../script/api.js"></script>
<script src="../../script/app.js"></script>
<script src="../../script/common.js"></script>
<script src="../../script/url.js"></script>
<script>
var vm;
var unReadMsgCount;
    apiready = function () {
        FNScanner  = api.require('FNScanner');
        unReadMsgCount = api.pageParam.unReadMsgCount;
        console.log()
        setBSImg();
        openFrames();
        initApp();
        addListeners();
    };

    function openFrames() {
        var bodyWidth = document.body.offsetWidth;
        var leftWidth = bodyWidth * 0.25;
        var rightWidth = bodyWidth - leftWidth;
        api.openFrame({
            name: 'mall_left',
            url: 'mall_left_frame.html',
            rect: {
                x: 0,
                y: 60,
                w: leftWidth,
                h: api.frameHeight-10,
            },
            bounces: false,
            vScrollBarEnabled: false,
            hScrollBarEnabled:false
        });

        api.openFrame({
            name: 'mall_right',
            url: 'mall_right_frame.html',
            rect: {
                x: leftWidth,
                y: 60,
                w: rightWidth,
                h: api.frameHeight,
            },
            bounces: false,
            vScrollBarEnabled: false,
            hScrollBarEnabled:false
        });


    }

    function initApp() {
        vm = new Vue({
            el: '#app',
            data: {
                BSImg: Vue.BSImg,
                unReadMsgCount: unReadMsgCount,
            },
            methods: {
                  scanner:function(){
                    FNScanner.open({
                        autorotation: true
                    }, function(ret, err) {
                        if (ret) {
                          url = ret.content;
                          if(url){
                            var domain = getPrefs("wap_url");
                            if(url.indexOf(domain) < 0 ){
                             pinet.alert('请扫描正确的推荐人二维码');
                             return;
                            }
                            var url = url.split("invite_code=");
                            invite_code = url[url.length-1];
                            if(url.length<2){
                              pinet.alert('请扫描正确的推荐人二维码');
                              return;
                            }
                            var params = {
                              invite_code:invite_code
                            }
                            if(!getPrefs('token')){
                                openWin("html/login/coderegister",params);
                            }else{
                              openWin("html/user/addshop",params);
                            }
                          }
                        } else {
                            alert(JSON.stringify(err));
                        }
                    });
}
            }
        });
    }

    function openSearch() {
        openWin('search');
    }

    function addListeners() {
        api.addEventListener({
            name: 'getUnReadMsgCount'
        }, function () {
            vm.unReadMsgCount = ret.value.count;
            api.setAppIconBadge({
                badge: ret.value.count
            });
        });

      }

      function openMessage() {
          if(!getPrefs('token')){
              reLogin();
          }
          openWin('../user/message');
      }
</script>
</html>
